<template>
  <div class="login">
    <App-header>
      <img slot="title" @click="prev" src="../assets/上一步.png" alt="">
      <p slot="city">密码登录</p>
    </App-header>
    <div class="accNumber" @submit.prevent="onSubmit">
      <div class="accNumber-item">
        <input type="text" v-model="username" placeholder="账号">
      </div>
      <div class="accNumber-item">
        <input :type="typeChange" v-model="password" placeholder="密码">
        <div :class="['btnSwitch', { 'btnSwitch__active' : btnLeft }]">
          <div @click="btnCircle" :class="['circleBtn', { 'circleBtn__active' : btnLeft }]"></div>
          <span>abc</span>
          <span>...</span>
        </div>
      </div>
      <div class="accNumber-item">
        <input type="text" v-model="code" placeholder="验证码">
        <div class="codeImg">
          <img :src="imgSrc.code" alt="">
          <div class="codeFont">
            <p @click="imgChange">看不清</p>
            <p @click="imgChange">换一张</p>
          </div>
        </div>
      </div>
    </div>
    <p class="colorFont">温馨提示：未注册过的账号，登录时将自动注册</p>
    <p class="colorFont">注册过的用户可凭借账号密码登录</p>
    <button @click="login">登录</button>
    <p @click="resetBtn" class="reset">重置密码?</p>
  </div>
</template>

<script>
import AppHeader from './AppHeader.vue'

export default {
  name: 'Login',
  data () {
    return {
      username: '',
      password: '',
      code: '',
      isActive: false,
      typeChange: 'password',
      imgSrc: []
    }
  },
  methods: {
    onSubmit () {
      return false
    },
    prev () {
      this.$router.go(-1)
    },
    btnCircle () {
      this.isActive = !this.isActive
      if (this.typeChange === 'password') {
        this.typeChange = 'text'
      } else {
        this.typeChange = 'password'
      }
    },
    login () {
      this.$http.login({
        username: this.username,
        password: this.password,
        captcha_code: this.code
      }).then(res => {
        window.console.log(res)
        this.username = res.data.username
        this.password = res.data.password
      }).catch(err => {
        window.console.log(err)
      })
    },
    imgChange () {
      this.$http.captachaCode({
        captcha_code: this.imgSrc
      }).then(res => {
        window.console.log(res)
        this.imgSrc = res.data
      }).catch(err => {
        window.console.log(err)
      })
    },
    resetBtn () {
      this.$router.push({ name: 'Reset' })
    }
  },
  components: { AppHeader },
  computed: {
    btnLeft () {
      return this.isActive
    }
  },
  created () {
    this.imgChange()
  }
}
</script>

<style scoped lang=scss>
  *{
    margin: 0px;
    padding: 0px;
    text-decoration: none;
  }
  .login{
    width: 100%;
    height: 1334px;
    background-color: #f5f5f5;
    .accNumber{
      width: 100%;
      height: 295px;
      margin-top: 30px;
      display: block;
      background-color: #fff;
      .accNumber-item{
        width: 90%;
        height: 35px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30px 37px;
        input{
          font-size: 34px;
          color: #666;
          border: none;
          outline: none;
        }
        .btnSwitch{
          background-color: #ccc;
          display: flex;
          justify-content: center;
          width: 80px;
          height: 32px;
          line-height: 32px;
          padding: 0px 5px;
          border: 1px solid #ccc;
          border-radius: 20px;
          position: relative;
          span{
            font-size: 19px;
            color: #fff;
          }
        }
        .circleBtn{
          transition: all .3s;
          position: absolute;
          top: -15px;
          z-index: 1;
          left: -15px;
          width: 60px;
          height: 60px;
          box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
          background-color: #f1f1f1;
          border-radius: 50%;
        }
        .btnSwitch__active{
          background-color: #4cd964;
        }
        .circleBtn__active{
          transform: translateX(60px);
        }
        .codeImg{
          width: 255px;
          height: 50px;
          display: flex;
          align-items: center;
          img{
            width: 165px;
            height: 70px;
          }
          .codeFont{
            width: 85px;
            height: 80px;
            display: flex;
            justify-content: center;
            flex-wrap: wrap;
            p{
              font-size: 28px;
            }
            p:first-child{
              color: #757575;
            }
            p:last-child{
              color: #3a95e9;
            }
          }
        }
      }
    }
    .colorFont{
      width: 90%;
      margin: 15px auto;
      font-size: 24px;
      color: #ff0100;
    }
    button{
      width: 90%;
      height: 95px;
      display: block;
      margin: 0px auto 50px;
      font-size: 33px;
      line-height: 95px;
      text-align: center;
      border-radius: 10px;
      outline: none;
      color: #fff;
      background-color: #4dd964;
      border: 1px solid #4dd964;
    }
    .reset{
      width: 90%;
      height: 30px;
      text-align: right;
      color: #3a95e9;
      font-size: 30px;
    }
  }
</style>
